Trunchate cargo config properly
authorMarkus Unterwaditzer <markus@unterwaditzer.net>
Tue, 16 Aug 2016 20:51:08 +0000 (22:51 +0200)
committerMarkus Unterwaditzer <markus@unterwaditzer.net>
Tue, 16 Aug 2016 21:00:40 +0000 (23:00 +0200)
src/cargo/util/config.rs
tests/registry.rs

index 329538663aea7b3590dc7f4f61920c3edcddbb39..21d68c1cef4fe607b5e0257422c72ac2152ab420 100644 (file)
@@ -732,5 +732,6 @@ pub fn set_config(cfg: &Config,
     let contents = toml::Value::Table(toml).to_string();
     try!(file.seek(SeekFrom::Start(0)));
     try!(file.write_all(contents.as_bytes()));
+    try!(file.file().set_len(contents.len() as u64));
     Ok(())
 }
index 0ddb55999d561b3d4231d0d24d5076970ea73e76..1a069f5628c8b7c262215cf47046d226351f2d07 100644 (file)
@@ -580,6 +580,19 @@ fn login_with_no_cargo_dir() {
                 execs().with_status(0));
 }
 
+#[test]
+fn login_with_differently_sized_token() {
+    // Verify that the configuration file gets properly trunchated.
+    let home = paths::home().join("new-home");
+    t!(fs::create_dir(&home));
+    assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"),
+                execs().with_status(0));
+    assert_that(cargo_process().arg("login").arg("lmao").arg("-v"),
+                execs().with_status(0));
+    assert_that(cargo_process().arg("login").arg("lmaolmaolmao").arg("-v"),
+                execs().with_status(0));
+}
+
 #[test]
 fn bad_license_file() {
     Package::new("foo", "1.0.0").publish();